package permission

import (
	"context"
	"private-domain-overseas-service/admin/business/api/internal/repository/permission"
	"private-domain-overseas-service/admin/business/api/internal/svc"
	"private-domain-overseas-service/admin/business/api/internal/types"
	"private-domain-overseas-service/pkg/xerr"
	"private-domain-overseas-service/tools/ent/adminrole"
	"private-domain-overseas-service/tools/ent/predicate"

	"github.com/zeromicro/go-zero/core/logx"
)

type AdminRoleDeleteLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// NewAdminRoleDeleteLogic - 后台角色删除接口
func NewAdminRoleDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminRoleDeleteLogic {
	return &AdminRoleDeleteLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// AdminRoleDelete - 后台角色删除接口
func (l *AdminRoleDeleteLogic) AdminRoleDelete(req *types.AdminRoleDeleteRequest) error {
	adminRoleDAO := permission.NewAdminRoleDao(l.ctx, l.svcCtx)

	// 删除角色
	adminRoleCond := make([]predicate.AdminRole, 0, 1)
	adminRoleCond = append(adminRoleCond, adminrole.IDEQ(int(req.Id)))
	err := adminRoleDAO.AdminRoleDelete(adminRoleCond)
	if err != nil {
		return xerr.ErrCodeMsg(xerr.ServerOperationExceptionError, err.Error())
	}
	return nil
}
